#include "Texture.hpp"

namespace MA {

Texture::Texture()
    : m_texture(nullptr), m_width(0), m_height(0) {

}

Texture::Texture(SDL_Renderer* renderer, std::string file)
    : m_texture(nullptr), m_width(0), m_height(0) {
    loadImage(renderer, file);
}

Texture::~Texture() {
    SDL_DestroyTexture(m_texture);
    m_texture = nullptr;
//    m_renderer = nullptr;
}

void Texture::loadImage(SDL_Renderer* renderer, std::string file) {
    m_texture = IMG_LoadTexture(renderer, file.c_str());
    if (m_texture == nullptr) {
        SDL_Log("Image can not load! IMG_Error: %s\n", IMG_GetError());
        return;
    }
    SDL_QueryTexture(m_texture, nullptr, nullptr, &m_width, &m_height);
}

const SDL_Texture* Texture::getTexPtr() {
    return m_texture;
}

void Texture::draw(SDL_Renderer* renderer, const SDL_Rect* srcArea, const SDL_Rect* dstArea) {
    SDL_RenderCopy(renderer, m_texture, srcArea, dstArea);
}

}
